'''
Created on Mar 10, 2013

@author: peterd

'''
import os

from scrapy.contrib.downloadermiddleware.httpproxy import HttpProxyMiddleware

class LiveHttpProxyMiddleware(HttpProxyMiddleware):
    def __init__(self):
        HttpProxyMiddleware.__init__(self)
        
    def _set_proxy(self, request, scheme):
        if os.environ.has_key('live_http_proxy'):            
            request.meta['proxy'] = os.environ['live_http_proxy']
        else:
            super(LiveHttpProxyMiddleware, self)._set_proxy(request, scheme) 